<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/vue.js"></script>
   
</head>
<body>  
    <!-- 组件之间的通信 非父子组件通信：中间人模式 -->
    <div id="app">
        <child-com1 ref="childCom1"></child-com1>
        <button @click="getCom">打招呼</button>
        <child-com2 :get-msg="childMsg"></child-com2>
    </div>
    <script>
        // com1传给中间人 --- 中间人传给com2
        Vue.component("childCom1",{
            template:`
                <div>
                    {{ msg }}
                </div>
            `,
            data(){
                return{
                    msg:"hello bro",
                    sendMsg:"good morning"
                }
            }
        })

        Vue.component("childCom2",{
            template:`
                <div>
                    {{ msg }}
                    {{ getMsg }}
                </div>
            `,
            data(){
                return {
                    msg:"hello bro too"
                }
            },
            props:{
                getMsg:{
                    type:String,
                    default:"myself"
                }
            }

        })
        var app = new Vue({
            el: "#app",
            data:{
                childMsg: ""
            },
            methods: {
                getCom(){
                    // console.log(this.$refs.myChild.msg)
                    this.childMsg = this.$refs.childCom1.sendMsg
                }
            }
        });
    </script>
</body>
</html>